package com.yiyi.credit.manage.abutment.ccxiapi.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yiyi.credit.manage.abutment.common.bean.APIResponse;
import com.yiyi.credit.manage.abutment.common.bean.ICINFOTIDAPIResponse;
import com.yiyi.credit.manage.abutment.common.bean.ICINFOAPIResponse;
import com.yiyi.credit.manage.abutment.common.bean.RISKINFOT1APIResponse;
import com.yiyi.credit.manage.abutment.common.enums.*;
import com.yiyi.credit.manage.abutment.common.utils.*;
import com.yiyi.credit.manage.abutment.service.CcxiService;
import com.yiyi.credit.manage.model.entity.InterfaceFlow;
import com.yiyi.credit.manage.model.vo.*;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/ccxi")
public class CcxiController {

    public static final Logger LOGGER = LoggerFactory.getLogger(CcxiController.class);

    @Value("${ccxi.account}")
    private String account;

    @Autowired
    private CcxiService ccxiService;

    /**-----------------------------------------------------------查询计费---------------------------------------------------------------------*/
    @ApiOperation(value = "个人身份验证", notes = "个人身份验证", response = APIResponse.class)
    @PostMapping("/identity/auth")
    public APIResponse identityAuth(@RequestBody @Valid IdentityAuthVo vo,BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.IDENTITY_AUTH.getPath());
        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.identityAuth(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.identityAuth(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        String data = null;
        if (map.get("data")!=null) data=map.get("data").toString();

        if("1".equals(mark) || interfaceFlow == null) {
            //个人身份验证2010,2011,2012状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE2010.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2011.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2012.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.IDENTITY_AUTH_SPEND.getValue(), InterfacePathEnum.IDENTITY_AUTH.getPath());
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);

    }

    @ApiOperation(value = "学历信息查询", notes = "学历信息查询", response = APIResponse.class)
    @PostMapping("/edu/query")
    public APIResponse eduQuery(@RequestBody @Valid EduQueryVo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.EDU_QUERY.getPath());
        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.eduQuery(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.eduQuery(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
            //学历信息查询0000,2001状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2001.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.EDU_QUERY_SPEND.getValue(), InterfacePathEnum.EDU_QUERY.getPath());
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "公共风险评分", notes = "公共风险评分", response = APIResponse.class)
    @PostMapping("/criminal/queryscore")
    public APIResponse criminalQueryScore(@RequestBody @Valid CriminalQueryScoreVo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.CRIMINAL_QUERYSCORE.getPath());
        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        InterfaceFlow interfaceFlow=null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.criminalQueryScore(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.criminalQueryScore(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
            //公共风险评分0000,2001状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2001.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.CRIMINAL_QUERYSCORE_SPEND.getValue(), InterfacePathEnum.CRIMINAL_QUERYSCORE.getPath());
        }
        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "个人履约能力综合查询", notes = "个人履约能力综合查询", response = APIResponse.class)
    @PostMapping("/credit/consumability")
    public APIResponse creditConsumability(@RequestBody @Valid CreditConsumabilityVo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.CREDIT_CONSUMABLIITY.getPath());
        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        InterfaceFlow interfaceFlow=null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.crditConsumability(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.crditConsumability(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
        //个人履约能力综合查询0000,2001状态才查得收费
        if(code.equals(CcxiReturnCodeEnum.CODE0000.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2001.getCode()))
            ccxiService.updateProjectToThirdCost(appid,account, SpendEnum.CREDIT_CONSUMABLIITY_SPEND.getValue(),InterfacePathEnum.CREDIT_CONSUMABLIITY.getPath());

        }
        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "多重风险检测详版", notes = "多重风险检测详版", response = APIResponse.class)
    @PostMapping("/credit/multiappl")
    public APIResponse creditMultiappl(@RequestBody @Valid CreditMultiapplVo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.CREDIT_MULTIAPPL.getPath());
        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        paraMap.put("mobile",vo.getMobile());
        InterfaceFlow interfaceFlow=null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.creditMultiappl(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.creditMultiappl(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMul(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONArray data = null;
        if (map.get("data")!=null) data=(JSONArray)map.get("data");
        if("1".equals(mark) || interfaceFlow == null) {
            //多重风险检测详版0000,2001,2021,2024状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2001.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2021.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2024.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.CREDIT_MULTIAPPL_SPEND.getValue(), InterfacePathEnum.CREDIT_MULTIAPPL.getPath());
        }
        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

/**-----------------------------------------------------------查得计费---------------------------------------------------------------------*/
    @ApiOperation(value = "个人综合信用评分查询", notes = "个人综合信用评分查询", response = APIResponse.class)
    @PostMapping("/credit/score/general/factors")
    public APIResponse creditScoreGeneralFactors(@RequestBody @Valid GeneralFactorsVo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.CREDIT_SCORE_GENERAL_FACTORS.getPath());
        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        paraMap.put("mobile",vo.getMobile());
        paraMap.put("card",vo.getCard());
        InterfaceFlow interfaceFlow=null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.creditScoreGeneralFactors(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.creditScoreGeneralFactors(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMapScore(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");
        if("1".equals(mark) || interfaceFlow == null) {
            //个人综合信用评分查询0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.CREDIT_SCORE_GENERAL_FACTORS_SPEND.getValue(), InterfacePathEnum.CREDIT_SCORE_GENERAL_FACTORS.getPath());
        }
        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "身份证归属地信息查询", notes = "身份证归属地信息查询", response = APIResponse.class)
    @PostMapping("/iden/locat")
    public APIResponse idenLocat(@RequestBody @Valid IdenLocatVo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.IDEN_LOCAT.getPath());
        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        InterfaceFlow interfaceFlow=null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.idenLocat(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.idenLocat(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");
        if("1".equals(mark) || interfaceFlow == null) {
            //身份证归属地信息查询0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.IDEN_LOCAT_SPEND.getValue(), InterfacePathEnum.IDEN_LOCAT.getPath());
        }
        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }


    @ApiOperation(value = "手机实名认证", notes = "手机实名认证", response = APIResponse.class)
    @PostMapping("/telecom/identity/3mo/t1")
    public APIResponse identity3moT1(@RequestBody @Valid Identity3moT1Vo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.TELECOM_IDENTITY.getPath());
        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        paraMap.put("mobile",vo.getMobile());
        InterfaceFlow interfaceFlow=null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.identity3moT1(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.identity3moT1(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");
        if("1".equals(mark) || interfaceFlow == null) {
            //手机实名认证2060,2061,2063状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE2060.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2061.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2063.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.TELECOM_IDENTITY_SPEND.getValue(), InterfacePathEnum.TELECOM_IDENTITY.getPath());
        }
        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }


    @ApiOperation(value = "四要素验证", notes = "四要素验证", response = APIResponse.class)
    @PostMapping("/auth/cncm/t2")
    public APIResponse autoCncmT2(@RequestBody @Valid AutoCncmVo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.AUTH_CNCM.getPath());
        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        paraMap.put("mobile",vo.getMobile());
        paraMap.put("card",vo.getCard());
        InterfaceFlow interfaceFlow=null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.autoCncmT2(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.autoCncmT2(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");
        if("1".equals(mark) || interfaceFlow == null) {
            //四要素验证2030,2031状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE2030.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2031.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.AUTH_CNCM_SPEND.getValue(), InterfacePathEnum.AUTH_CNCM.getPath());
        }
        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "信贷中介信息查询", notes = "信贷中介信息查询", response = APIResponse.class)
    @PostMapping("/riskinfo/credit")
    public APIResponse riskinfoCredit(@RequestBody @Valid RiskinfoCreditlVo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.RISKINFO_CREDIT.getPath());
        paraMap.put("name",vo.getName());
        paraMap.put("mobile",vo.getMobile());
        InterfaceFlow interfaceFlow=null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.riskinfoCredit(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.riskinfoCredit(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMapRis(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONArray data = null;
        if (map.get("data")!=null) data=(JSONArray)map.get("data");
        if("1".equals(mark) || interfaceFlow == null) {
            //信贷中介信息查询0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.RISKINFO_CREDIT_SPEND.getValue(), InterfacePathEnum.RISKINFO_CREDIT.getPath());
        }
        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "银行卡BIN信息查询", notes = "银行卡BIN信息查询", response = APIResponse.class)
    @PostMapping("/bank/cardbin")
    public APIResponse bankCardbin(@RequestBody @Valid BankCardBinVo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.BANK_CARDBIN.getPath());
        paraMap.put("card",vo.getCard());
        InterfaceFlow interfaceFlow=null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.bankCardbin(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.bankCardbin(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");
        if("1".equals(mark) || interfaceFlow == null) {
            //银行卡BIN信息查询0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.BANK_CARDBIN_SPEND.getValue(), InterfacePathEnum.BANK_CARDBIN.getPath());
        }
        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }


    @ApiOperation(value = "风险信息标准查询", notes = "风险信息标准查询", response = RISKINFOT1APIResponse.class)
    @PostMapping("/riskinfo/t1")
    public RISKINFOT1APIResponse riskinfoT1(@RequestBody @Valid RiskinfoT1Vo vo,BindingResult result) throws Exception {

        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new RISKINFOT1APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new RISKINFOT1APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new RISKINFOT1APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new RISKINFOT1APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.RISKINFOT1.getPath());
        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        paraMap.put("type",vo.getType());
        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.riskinfoT1(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.riskinfoT1(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMapRisT1(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        String totalNum = map.get("totalNum").toString();
        String tid = map.get("tid").toString();
        JSONArray data = null;
        if (map.get("data")!=null) data=(JSONArray)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
            //风险信息标准查询,0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.RISKINFOT1_SPEND.getValue(), InterfacePathEnum.RISKINFOT1.getPath());
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new RISKINFOT1APIResponse<>(tid,totalNum,data,code,msg,requestNo,createTime);
    }


    @ApiOperation(value = "判决文书详情查询", notes = "判决文书详情查询", response = APIResponse.class)
    @PostMapping("/riskinfo/t1/detail")
    public APIResponse riskinfoT1Detail(@RequestBody @Valid RiskinfoT1DetailVo vo,BindingResult result) throws Exception {

        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.RISKINFOT1DETAIL.getPath());
        paraMap.put("tid",vo.getTid());
        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.riskinfoT1Detail(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.riskinfoT1Detail(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");

        /*if("1".equals(mark) || interfaceFlow == null) {
            //风险信息标准查询,0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.RISKINFOT1DETAIL_SPEND.getValue(), InterfacePathEnum.RISKINFOT1DETAIL.getPath());
        }*/

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);

    }

    @ApiOperation(value = "个人交易报告查询", notes = "个人交易报告查询", response = APIResponse.class)
    @PostMapping("/trans/report/t2")
    public APIResponse transReportT2(@RequestBody @Valid TransReportT2Vo vo,BindingResult result) throws Exception {

        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.TRANSREPORTT2.getPath());

        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        paraMap.put("mobile",vo.getMobile());
        paraMap.put("card",vo.getCard());

        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.transReportT2(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.transReportT2(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");
        /*String dataStr = JSONObject.toJSONString(data);
        data  = JSONObject.parseObject(dataStr);*/
        if("1".equals(mark) || interfaceFlow == null) {
            //风险信息标准查询,0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.TRANSREPORTT2_SPEND.getValue(), InterfacePathEnum.TRANSREPORTT2.getPath());
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);

    }

    @ApiOperation(value = "个人职业资格证书查询", notes = "个人职业资格证书查询", response = APIResponse.class)
    @PostMapping("/cert")
    public APIResponse cert(@RequestBody @Valid CertVo vo,BindingResult result) throws Exception {

        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.VEHICLEINFO.getPath());

        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());

        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.cert(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.cert(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMul(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONArray data = null;
        if (map.get("data")!=null) data=(JSONArray)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
            //风险信息标准查询,0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.CERT_SPEND.getValue(), InterfacePathEnum.CERT.getPath());
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "历史车产信息查询", notes = "历史车产信息查询", response = APIResponse.class)
    @PostMapping("/vehicle/info")
    public APIResponse vehicleInfo(@RequestBody @Valid VehicleInfoVo vo,BindingResult result) throws Exception {

        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.VEHICLEINFO.getPath());

        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());

        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.vehicleInfo(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.vehicleInfo(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMul(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONArray data = null;
        if (map.get("data")!=null) data=(JSONArray)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
            //风险信息标准查询,0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.VEHICLEINFO_SPEND.getValue(), InterfacePathEnum.VEHICLEINFO.getPath());
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "运营商消费水平查询", notes = "运营商消费水平查询", response = APIResponse.class)
    @PostMapping("/telecom/consumability")
    public APIResponse telecomConsumability(@RequestBody @Valid ConsumabilityVo vo,BindingResult result) throws Exception {

        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.TELECOMCONSUMABILITY.getPath());

        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        paraMap.put("mobile",vo.getMobile());

        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.telecomConsumability(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.telecomConsumability(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
            //风险信息标准查询,0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.TELECOMCONSUMABILITY_SPEND.getValue(), InterfacePathEnum.TELECOMCONSUMABILITY.getPath());
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "运营商状态和时长查询", notes = "运营商状态和时长查询", response = APIResponse.class)
    @PostMapping("/telecom/statetime")
    public APIResponse telecomStatetime(@RequestBody @Valid StatetimeVo vo,BindingResult result) throws Exception {

       long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.TELECOMSTATETIME.getPath());

        paraMap.put("cid",vo.getCid());
        paraMap.put("name",vo.getName());
        paraMap.put("mobile",vo.getMobile());

        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.telecomStatetime(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.telecomStatetime(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
            //风险信息标准查询,0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.TELECOMSTATETIME_SPEND.getValue(), InterfacePathEnum.TELECOMSTATETIME.getPath());
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "工商信息查询", notes = "工商信息查询", response = ICINFOTIDAPIResponse.class)
    @PostMapping("/icinfo/category")
    public ICINFOTIDAPIResponse icinfoCategory(@RequestBody @Valid IcinfoCategoryVo vo,BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new ICINFOTIDAPIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new ICINFOTIDAPIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new ICINFOTIDAPIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new ICINFOTIDAPIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.ICINFO_CATEGORY.getPath());

        paraMap.put("type",vo.getType());
        paraMap.put("cat",vo.getCat());
        paraMap.put("key",vo.getKey());

        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.icinfoCategory(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.icinfoCategory(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        String tid = null;
        if(map.get("tid") != null)
            tid = map.get("tid").toString();

        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
            //风险信息标准查询,0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()) || code.equals(CcxiReturnCodeEnum.CODE2001.getCode())){
                if("1".equals(vo.getType()) || "2".equals(vo.getType()))
                    ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.ICINFO_CATEGORY_SPEND.getValue(), InterfacePathEnum.ICINFO_CATEGORY.getPath());
                else
                    ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.ICINFO_CATEGORY_PERSON_SPEND.getValue(), InterfacePathEnum.ICINFO_CATEGORY.getPath());
            }
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new ICINFOTIDAPIResponse<>(tid,data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "根据流水号,自然人姓名查询工商信息", notes = "根据流水号,自然人姓名查询工商信息", response = APIResponse.class)
    @PostMapping("/icinfo/category/person/tid")
    public APIResponse icinfocategoryPerson(@RequestBody @Valid IcinfoCategoryPersonTidVo vo,BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.ICINFO_CATEGORY_PERSON_TID.getPath());

        paraMap.put("type",vo.getType());
        paraMap.put("cat",vo.getCat());
        paraMap.put("key",vo.getKey());

        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.icinfocategoryPerson(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.icinfocategoryPerson(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "企业信用报告查询", notes = "企业信用报告查询", response = ICINFOAPIResponse.class)
    @PostMapping("/icinfo/report")
    public ICINFOAPIResponse icinfoReport(@RequestBody @Valid IcinfoReportVo vo, BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new ICINFOAPIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new ICINFOAPIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new ICINFOAPIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new ICINFOAPIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.ICINFO_REPORT.getPath());

        paraMap.put("name",vo.getName());
        paraMap.put("cid",vo.getCid());

        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.icinfoReport(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.icinfoReport(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowicinfo(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONArray data = null;
        if (map.get("data")!=null) data=(JSONArray)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
            //风险信息标准查询,0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.ICINFO_REPORT_SPEND.getValue(), InterfacePathEnum.ICINFO_REPORT.getPath());
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new ICINFOAPIResponse<>(data,code,msg,requestNo,createTime);
    }

    @ApiOperation(value = "航空出行画像", notes = "航空出行画像", response = APIResponse.class)
    @PostMapping("/airtravel/trareport")
    public APIResponse airtravelTrareport(@RequestBody @Valid AirtravelTrareportVo vo,BindingResult result) throws Exception {
        long start = System.currentTimeMillis();
        String reqDate = JSONObject.toJSONString(vo);
        LOGGER.info("{}平台请求参数:{}",vo.getAppId(),reqDate);
        if(result.hasErrors()){
            return new APIResponse(ResponseCode.PARAM_ERR.getCode(),result.getFieldError().getDefaultMessage());
        }
        String appid = vo.getAppId();
        String privateKey = AppIdEnum.getPrivateKeyByCode(appid);
        if(privateKey==null) return new APIResponse<>(ResponseCode.NOT_APPID);

        boolean bool=SignatureUtils.checkSign(reqDate,privateKey);
        if(!bool) return new APIResponse<>(ResponseCode.SIGN_ERR);

        List<InterfaceFlow> list=ccxiService.uniqueRequestNo(appid,vo.getRequestNo());
        if(list.size()>0) return new APIResponse<>(ResponseCode.REQUESTNO_REPEAT, vo.getRequestNo());

        Map<String, Object> map = null;
        Map<String, Object> paraMap = new HashMap<String, Object>();
        paraMap.put("interfaceType",InterfacePathEnum.AIRTRAVEL_TRAREPORT.getPath());

        paraMap.put("name",vo.getName());
        paraMap.put("cid",vo.getCid());
        paraMap.put("month",vo.getMonth());

        InterfaceFlow interfaceFlow = null;

        String mark = vo.getMark();
        if(StringUtils.isNotEmpty(mark) && "1".equals(mark)){
            map = ccxiService.airtravelTrareport(reqDate,appid,vo.getRequestNo());
        }else {
            interfaceFlow=ccxiService.queryInterfaceFlowByReqData(paraMap);
            if(interfaceFlow == null){
                map = ccxiService.airtravelTrareport(reqDate,appid,vo.getRequestNo());
            }else{
                paraMap.put("requestNo",vo.getRequestNo());
                map = ccxiService.interfaceFlowReMap(interfaceFlow,vo.getRequestNo());
            }
        }

        String respStr = map.get("respStr").toString();
        String code = map.get("code").toString();
        String msg = map.get("msg").toString();
        String requestNo = map.get("requestNo").toString();
        String createTime = map.get("createTime").toString();
        JSONObject data = null;
        if (map.get("data")!=null) data=(JSONObject)map.get("data");

        if("1".equals(mark) || interfaceFlow == null) {
            //风险信息标准查询,0000状态才查得收费
            if (code.equals(CcxiReturnCodeEnum.CODE0000.getCode()))
                ccxiService.updateProjectToThirdCost(appid, account, SpendEnum.AIRTRAVEL_TRAREPORT_SPEND.getValue(), InterfacePathEnum.AIRTRAVEL_TRAREPORT.getPath());
        }

        LOGGER.info("接口耗时:{}ms ",System.currentTimeMillis()-start);
        return new APIResponse<>(data,code,msg,requestNo,createTime);
    }

    }
